# P383-P388
# 士兵突击
# 需求
# 1、士兵许三多有一把AK47
# 2、士兵可以开火
# 3、枪能够发射子弹
# 4、枪装填子弹--增加子弹数量
class Solider:
    name = None
    gun = None

    def __init__(self, name = "美队", gun = None):
        self.name = name
        self.gun = gun

    def fire(self):
        if self.gun == None:
            print("士兵还没有枪")
            return False

        self.gun.consume()



class Weapon:
    model = None
    bullet = 0

    def __init__(self, model):
        self.model = model

    def loading(self, bullet):
        print("子弹数量增加%s" % bullet)
        self.bullet += bullet
        print("剩余子弹数量%s" % self.bullet)

    def consume(self):
        """
        发射子弹
        """
        if self.bullet <= 0:
            print("没子弹了，不能开枪呀")
            return False
        print("子弹-1")
        self.bullet -= 1
        print("剩余子弹数量%s" % self.bullet)

# 开始实例化士兵和武器
xu_san_duo_object = Solider("许三多", Weapon("AK47"))
# 装填子弹
xu_san_duo_object.gun.loading(30)
# 发射子弹
xu_san_duo_object.gun.consume()
xu_san_duo_object.gun.consume()
xu_san_duo_object.gun.consume()
# 装填子弹
xu_san_duo_object.gun.loading(30)
